﻿<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Inner.Master" CodeBehind="BookAppointment.aspx.vb" Inherits="LecturerAppointmentSystem.BookAppointment" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="Style.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <div>
        <asp:UpdatePanel ID="DateUpdatePanel" runat="server">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="tb_Date" EventName="TextChanged" />
            </Triggers>
            <ContentTemplate>
                <table align="center" width="100%">
                    <tr class="tr">
                        <td align="right" class="style2" valign="top" colspan="6">
                            <asp:Label ID="lblDateError" runat="server" CssClass="hideControl" ForeColor="Red"></asp:Label>&nbsp;
                        </td>
                    </tr>
                    <tr class="tr">
                        <td class="style2" colspan="6" valign="top">
                            Please enter a search criteria.<br />
                            <br />
                            Please note: Only tutors with free slots will be shown.</td>
                    </tr>
                    <tr class="tr">
                        <td align="right" class="style2" valign="top">
                            <asp:Label ID="lbl_Name" runat="server" AssociatedControlID="tb_Name" Text="Name: "></asp:Label>
                            &nbsp;
                        </td>
                        <td align="left" class="style2" valign="top">
                            <asp:TextBox ID="tb_Name" runat="server"></asp:TextBox>
                        </td>
                        <td align="right" class="style2" valign="top">
                            <asp:Label ID="lbl_Date" runat="server" AssociatedControlID="tb_Date" Text="Date: "></asp:Label>
                            &nbsp;
                        </td>
                        <td align="left" class="style2" valign="top">
                            <asp:TextBox ID="tb_Date" runat="server" AutoPostBack="true" Width="70%" OnTextChanged="validateDate"></asp:TextBox>
                            <asp:CalendarExtender ID="tb_Date_CalendarExtender" runat="server" Enabled="True"
                                TargetControlID="tb_Date" PopupButtonID="btn_Calendar" Format="dd/MM/yyyy" SelectedDate="<%# Date.Today %>"
                                FirstDayOfWeek="Monday" Animated="true" OnClientDateSelectionChanged="checkDate">
                            </asp:CalendarExtender>
                            <asp:ImageButton ID="btn_Calendar" runat="server" Height="25px" ImageUrl="~/Images/calendarIcon.png"
                                Width="25px" />
                            <br />
                            <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="tb_Date"
                                Display="Dynamic" ErrorMessage="Invalid Date" Operator="DataTypeCheck" Type="Date">
                            </asp:CompareValidator>
                            <br />
                        </td>
                        <td align="right" class="style2" valign="top">
                            <asp:Label ID="lbl_Faculty" runat="server" AssociatedControlID="ddl_Faculty" Text="Faculty: "></asp:Label>
                        </td>
                        <td align="left" class="style2" valign="top">
                            <asp:DropDownList ID="ddl_Faculty" runat="server" DataSourceID="FacultyDataSource"
                                DataTextField="FacultyName" DataValueField="ID" OnDataBound="AddBlankItem" Width="80px">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr class="tr">
                        <td align="right" class="style2" valign="top">
                            &nbsp;
                        </td>
                        <td align="left" class="style2" valign="top">
                            &nbsp;
                        </td>
                        <td align="right" class="style2" valign="top">
                            &nbsp;
                        </td>
                        <td align="left" class="style2" valign="top">
                            &nbsp;
                        </td>
                        <td align="left" class="style2" valign="top">
                            &nbsp;
                        </td>
                        <td align="left" class="style2" valign="top">
                            <asp:Button ID="btn_Search" runat="server" Text="Search" />
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>
        <br />
        <asp:Label ID="lbl_Search" Visible="false" runat="server" Text='<%# "Name: " & tb_Name.text & " Date: " & tb_Date.Text & " Faculty: " & ddl_Faculty.SelectedIndex %>'></asp:Label>
       
    </div>
    <div style="margin-left:15%; margin-right:15%; margin-top:2%; margin-bottom:2%">
        <asp:MultiView ID="SearchMultiView" runat="server">
            <asp:View ID="DefaultView" runat="server">
            </asp:View>
            <asp:View ID="SearchByNameView" runat="server">
                <asp:GridView ID="SearchByNameGridView" runat="server" EnableModelValidation="True"
                    CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" AllowSorting="True"
                    AutoGenerateColumns="False" DataSourceID="SearchByName" CssClass="GridViewClass">
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <Columns>
                    <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" HeaderStyle-CssClass="hideControl">
                        <HeaderStyle CssClass="hideControl" />
                        <ItemStyle CssClass="hideControl" Width="1px"/></asp:BoundField>
                        <asp:BoundField DataField="AppointmentDate" DataFormatString="{0:D}" HeaderText="Date"
                            SortExpression="AppointmentDate" />
                        <asp:BoundField DataField="TimeSlot" HeaderText="Time" SortExpression="TimeSlot" />
                        <asp:BoundField DataField="Place" HeaderText="Place" SortExpression="Place" />
                        <asp:TemplateField HeaderText="Tutor Name"><ItemTemplate><asp:HyperLink ID="ViewTutorAppointments" runat="server" ToolTip="Click to view tutor's appointments"
                                    NavigateUrl='<%# Eval("Fkid_UserId", "BookAppointment.aspx?ID={0}") %>' Text='<%# Eval("FirstName") & " " & Eval("LastName") %>'></asp:HyperLink></ItemTemplate></asp:TemplateField>
                        <asp:TemplateField HeaderText="Faculty" SortExpression="FacultyName"><EditItemTemplate><asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FacultyName") %>'></asp:TextBox></EditItemTemplate><ItemTemplate><asp:HyperLink ID="ViewFacultyAppointments" runat="server" ToolTip="View all available appointments in this faculty"
                                    NavigateUrl='<%# Eval("Fkid_Faculty", "BookAppointment.aspx?faculty={0}") %>' Text='<%# Eval("FacultyName") %>'></asp:HyperLink></ItemTemplate></asp:TemplateField>
                        <asp:BoundField DataField="Fkid_UserId" HeaderText="Lecturer User Id" Visible="False" />
                        <asp:TemplateField><ItemTemplate><asp:Button ID="btn_Book" runat="server" Text="Book this slot" OnClick="btn_Book_Click" /></ItemTemplate></asp:TemplateField>
                    </Columns>
                    <EditRowStyle BackColor="#999999" />
                    <EmptyDataTemplate>
                        Your search has yielded no results.<br /> Please try again.
                    </EmptyDataTemplate>
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                </asp:GridView>
                <asp:SqlDataSource ID="SearchByName" runat="server" ConnectionString="<%$ ConnectionStrings:AppointmentsConnectionString %>"
                    ProviderName="<%$ ConnectionStrings:AppointmentsConnectionString.ProviderName %>"
                    SelectCommand="SELECT [ID], [Fkid_Faculty], [Fkid_UserId], [AppointmentDate], [TimeSlot], [Place], [FirstName], [LastName], [FacultyName] FROM [Test2AppointmentsAndLecturerDetailsQuery] WHERE ([UniversityName] = ?) AND ([AppointmentDate] &gt;= ?) AND (([FirstName] LIKE '%' + ? + '%') OR ([LastName] LIKE '%' + ? + '%'))">
                    <SelectParameters>
                        <asp:SessionParameter Name="UniversityName" SessionField="University" 
                            Type="Int32" />
                        <asp:ControlParameter ControlID="lbl_TodaysDate" DefaultValue="" 
                            Name="AppointmentDate" PropertyName="Text" Type="DateTime" />
                        <asp:QueryStringParameter DefaultValue="" Name="FirstName" 
                            QueryStringField="name" Type="String" />
                        <asp:QueryStringParameter Name="LastName" QueryStringField="name" 
                            Type="String" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </asp:View>
            <asp:View ID="SearchByUserIdView" runat="server">
                <asp:GridView ID="SearchByUserIdGridView" runat="server" EnableModelValidation="True"
                    CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" AllowSorting="True"
                    AutoGenerateColumns="False" DataSourceID="SearchByUserId">
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <Columns>
                    <asp:BoundField DataField="ID" HeaderText="Appointment ID" Visible="False" />
                        <asp:BoundField DataField="Fkid_UserId" HeaderText="Fkid_UserId" 
                            SortExpression="Fkid_UserId" Visible="False" />
                        <asp:BoundField DataField="AppointmentDate" DataFormatString="{0:D}" 
                            HeaderText="Date" />
                        <asp:BoundField DataField="TimeSlot" HeaderText="Time" 
                            SortExpression="TimeSlot" />
                        <asp:BoundField DataField="Place" HeaderText="Place" SortExpression="Place" />
                    </Columns>
                    <EditRowStyle BackColor="#999999" />
                    <EmptyDataTemplate>
                        Your search has yielded no results.<br /> Please try again.
                    </EmptyDataTemplate>
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                </asp:GridView>
                <asp:SqlDataSource ID="SearchByUserId" runat="server" ConnectionString="<%$ ConnectionStrings:AppointmentsConnectionString %>"
                    ProviderName="<%$ ConnectionStrings:AppointmentsConnectionString.ProviderName %>"
                    SelectCommand="SELECT [ID], [Fkid_Faculty], [Fkid_UserId], [TimeSlot], [Place], [FirstName], [LastName], [FacultyName] FROM [Test2AppointmentsAndLecturerDetailsQuery] WHERE (([UniversityName] = ?) AND ([AppointmentDate] &gt;= ?) AND ([Fkid_UserId] = ?))">
                    <SelectParameters>
                        <asp:SessionParameter Name="UniversityName" SessionField="University" Type="Int32" />
                        <asp:ControlParameter ControlID="lbl_TodaysDate" Name="AppointmentDate" 
                    PropertyName="Text" Type="DateTime" />
                        <asp:QueryStringParameter Name="Fkid_UserId" QueryStringField="ID" Type="Int32" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </asp:View>
            <asp:View ID="SearchByDateView" runat="server">
                <asp:GridView ID="SearchByDateGridView" runat="server" EnableModelValidation="True"
                    CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" AllowSorting="True"
                    AutoGenerateColumns="False" DataSourceID="SearchByDate">
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <Columns>
                    <asp:BoundField DataField="ID" HeaderText="Appointment ID" Visible="False" />
                        <asp:BoundField DataField="TimeSlot" HeaderText="TimeSlot" SortExpression="TimeSlot" />
                        <asp:BoundField DataField="Place" HeaderText="Place" SortExpression="Place" />
                        <asp:TemplateField HeaderText="Tutor Name"><ItemTemplate><asp:HyperLink ID="HyperLink1" runat="server" ToolTip="Click to view profile page"
                                    NavigateUrl='<%# Eval("Fkid_UserId", "BookAppointment.aspx?ID={0}") %>' Text='<%# Eval("FirstName") & " " & Eval("LastName") %>'></asp:HyperLink></ItemTemplate></asp:TemplateField>
                        <asp:TemplateField HeaderText="Faculty" SortExpression="FacultyName"><EditItemTemplate><asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FacultyName") %>'></asp:TextBox></EditItemTemplate><ItemTemplate><asp:HyperLink ID="HyperLink1" runat="server" ToolTip="View all available appointments in this faculty"
                                    NavigateUrl='<%# Eval("Fkid_Faculty", "BookAppointment.aspx?faculty={0}") %>' Text='<%# Eval("FacultyName") %>'></asp:HyperLink></ItemTemplate></asp:TemplateField>
                    </Columns>
                    <EditRowStyle BackColor="#999999" />
                    <EmptyDataTemplate>
                        Your search has yielded no results.<br /> Please try again.
                    </EmptyDataTemplate>
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                </asp:GridView>
                <asp:SqlDataSource ID="SearchByDate" runat="server" ConnectionString="<%$ ConnectionStrings:AppointmentsConnectionString %>"
                    ProviderName="<%$ ConnectionStrings:AppointmentsConnectionString.ProviderName %>"
                    SelectCommand="SELECT [ID], [Fkid_Faculty], [Fkid_UserId], [TimeSlot], [Place], [FirstName], [LastName], [FacultyName] FROM [Test2AppointmentsAndLecturerDetailsQuery] WHERE (([UniversityName] = ?) AND ([AppointmentDate] = ?))">
                    <SelectParameters>
                        <asp:SessionParameter Name="UniversityName" SessionField="University" Type="Int32" />
                        <asp:QueryStringParameter Name="AppointmentDate" QueryStringField="date" Type="DateTime" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </asp:View>
            <asp:View ID="SearchByFacultyView" runat="server">
                <asp:GridView ID="SearchByFacultyGridView" runat="server" EnableModelValidation="True"
                    CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" AllowSorting="True"
                    AutoGenerateColumns="False" DataSourceID="SearchByFaculty">
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <Columns>
                    <asp:BoundField DataField="ID" HeaderText="Appointment ID" Visible="False" />
                        <asp:BoundField DataField="AppointmentDate" HeaderText="Date" 
                            SortExpression="AppointmentDate" DataFormatString="{0:D}" />
                        <asp:BoundField DataField="TimeSlot" HeaderText="Time" 
                            SortExpression="TimeSlot" />
                        <asp:BoundField DataField="Place" HeaderText="Place" SortExpression="Place" />
                        <asp:TemplateField HeaderText="Tutor Name"><ItemTemplate><asp:HyperLink ID="HyperLink1" runat="server" ToolTip="Click to view profile page"
                                    NavigateUrl='<%# Eval("Fkid_UserId", "BookAppointment.aspx?ID={0}") %>' Text='<%# Eval("FirstName") & " " & Eval("LastName") %>'></asp:HyperLink></ItemTemplate></asp:TemplateField>
                    </Columns>
                    <EditRowStyle BackColor="#999999" />
                    <EmptyDataTemplate>
                        Your search has yielded no results.<br /> Please try again.
                    </EmptyDataTemplate>
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                </asp:GridView>
                <asp:SqlDataSource ID="SearchByFaculty" runat="server" ConnectionString="<%$ ConnectionStrings:AppointmentsConnectionString %>"
                    ProviderName="<%$ ConnectionStrings:AppointmentsConnectionString.ProviderName %>"
                    
                    SelectCommand="SELECT [ID], [Fkid_Faculty], [Fkid_UserId], [AppointmentDate], [TimeSlot], [Place], [FirstName], [LastName] FROM [Test2AppointmentsAndLecturerDetailsQuery] WHERE (UniversityName = ?) AND ([AppointmentDate] &gt;= ?) AND (Fkid_Faculty = ?)">
                    <SelectParameters>
                        <asp:SessionParameter Name="UniversityName" SessionField="University" />
                        <asp:ControlParameter ControlID="lbl_TodaysDate" Name="AppointmentDate" 
                    PropertyName="Text" Type="DateTime" />
                        <asp:QueryStringParameter DefaultValue="" Name="Fkid_Faculty" QueryStringField="faculty" />
     
                    </SelectParameters>
                </asp:SqlDataSource>
            </asp:View>
            <asp:View ID="SearchByNameAndDateView" runat="server">
                <asp:GridView ID="SearchByNameAndDateGridView" runat="server" EnableModelValidation="True"
                    CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" AllowSorting="True"
                    AutoGenerateColumns="False" DataSourceID="SearchByNameAndDate">
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <Columns>
                    <asp:BoundField DataField="ID" HeaderText="Appointment ID" Visible="False" />
                        <asp:BoundField DataField="TimeSlot" HeaderText="Time" 
                            SortExpression="TimeSlot" />
                        <asp:BoundField DataField="Place" HeaderText="Place" SortExpression="Place" />
                        <asp:TemplateField HeaderText="Tutor Name"><ItemTemplate><asp:HyperLink ID="HyperLink1" runat="server" ToolTip="Click to view profile page"
                                    NavigateUrl='<%# Eval("Fkid_UserId", "BookAppointment.aspx?ID={0}") %>' Text='<%# Eval("FirstName") & " " & Eval("LastName") %>'></asp:HyperLink></ItemTemplate></asp:TemplateField>
                        <asp:TemplateField HeaderText="Faculty" SortExpression="FacultyName"><EditItemTemplate><asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FacultyName") %>'></asp:TextBox></EditItemTemplate><ItemTemplate><asp:HyperLink ID="HyperLink1" runat="server" ToolTip="View all available appointments in this faculty"
                                    NavigateUrl='<%# Eval("Fkid_Faculty", "BookAppointment.aspx?faculty={0}") %>' Text='<%# Eval("FacultyName") %>'></asp:HyperLink></ItemTemplate></asp:TemplateField>
                    </Columns>
                    <EditRowStyle BackColor="#999999" />
                    <EmptyDataTemplate>
                        Your search has yielded no results.<br /> Please try again.
                    </EmptyDataTemplate>
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                </asp:GridView>
                <asp:SqlDataSource ID="SearchByNameAndDate" runat="server" ConnectionString="<%$ ConnectionStrings:AppointmentsConnectionString %>"
                    ProviderName="<%$ ConnectionStrings:AppointmentsConnectionString.ProviderName %>"
                    SelectCommand="SELECT [ID], [Fkid_Faculty], [Fkid_UserId], [TimeSlot], [Place], [FirstName], [LastName], [FacultyName] FROM [Test2AppointmentsAndLecturerDetailsQuery] WHERE (UniversityName = ?) AND ((FirstName LIKE '%' + ? + '%') OR (LastName LIKE '%' + ? + '%')) AND (AppointmentDate = ?)">
                    <SelectParameters>
                        <asp:SessionParameter Name="UniversityName" SessionField="University" />
                        <asp:QueryStringParameter Name="FirstName" QueryStringField="name" />
                        <asp:QueryStringParameter Name="LastName" QueryStringField="name" />
                        <asp:QueryStringParameter Name="AppointmentDate" QueryStringField="date" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </asp:View>
            <asp:View ID="SearchByNameAndFacultyView" runat="server">
                <asp:GridView ID="SearchByNameAndFacultyGridView" runat="server" EnableModelValidation="True"
                    CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" AllowSorting="True"
                    AutoGenerateColumns="False" DataSourceID="SearchByNameAndFaculty">
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <Columns>
                    <asp:BoundField DataField="ID" HeaderText="Appointment ID" Visible="False" />
                        <asp:BoundField DataField="AppointmentDate" HeaderText="Date" SortExpression="AppointmentDate" />
                        <asp:BoundField DataField="TimeSlot" HeaderText="Time" SortExpression="TimeSlot" />
                        <asp:BoundField DataField="Place" HeaderText="Place" SortExpression="Place" />
                        <asp:TemplateField HeaderText="Tutor Name"><ItemTemplate><asp:HyperLink ID="HyperLink1" runat="server" ToolTip="Click to view profile page"
                                    NavigateUrl='<%# Eval("Fkid_UserId", "BookAppointment.aspx?ID={0}") %>' Text='<%# Eval("FirstName") & " " & Eval("LastName") %>'></asp:HyperLink></ItemTemplate></asp:TemplateField>
                    </Columns>
                    <EditRowStyle BackColor="#999999" />
                    <EmptyDataTemplate>
                        Your search has yielded no results.<br /> Please try again.
                    </EmptyDataTemplate>
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                </asp:GridView>
                <asp:SqlDataSource ID="SearchByNameAndFaculty" runat="server" ConnectionString="<%$ ConnectionStrings:AppointmentsConnectionString %>"
                    ProviderName="<%$ ConnectionStrings:AppointmentsConnectionString.ProviderName %>"
                    SelectCommand="SELECT [ID], [Fkid_Faculty], [Fkid_UserId], [AppointmentDate], [TimeSlot], [Place], [FirstName], [LastName] FROM [Test2AppointmentsAndLecturerDetailsQuery] WHERE (UniversityName = ?) AND ([AppointmentDate] &gt;= ?) AND ((FirstName LIKE '%' + ? + '%') OR (LastName LIKE '%' + ? + '%')) AND (Fkid_Faculty = ?)">
                    <SelectParameters>
                        <asp:SessionParameter Name="UniversityName" SessionField="University" />
                        <asp:ControlParameter ControlID="lbl_TodaysDate" Name="AppointmentDate" 
                    PropertyName="Text" Type="DateTime" />
                        <asp:QueryStringParameter Name="FirstName" QueryStringField="name" />
                        <asp:QueryStringParameter Name="LastName" QueryStringField="name" />
                        <asp:QueryStringParameter Name="Fkid_Faculty" QueryStringField="faculty" />
                        </SelectParameters>
                </asp:SqlDataSource>
            </asp:View>
            <asp:View ID="SearchByDateAndFacultyView" runat="server">
                <asp:GridView ID="SearchByDateAndFacultyGridView" runat="server" EnableModelValidation="True"
                    CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" AllowSorting="True"
                    AutoGenerateColumns="False" DataSourceID="SearchByDateAndFaculty">
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <Columns>
                    <asp:BoundField DataField="ID" HeaderText="Appointment ID" Visible="False" />
                        <asp:BoundField DataField="AppointmentDate" HeaderText="Date" SortExpression="AppointmentDate" />
                        <asp:BoundField DataField="TimeSlot" HeaderText="Time" SortExpression="TimeSlot" />
                        <asp:BoundField DataField="Place" HeaderText="Place" SortExpression="Place" />
                        <asp:TemplateField HeaderText="Tutor Name"><ItemTemplate><asp:HyperLink ID="HyperLink1" runat="server" ToolTip="Click to view profile page"
                                    NavigateUrl='<%# Eval("Fkid_UserId", "BookAppointment.aspx?ID={0}") %>' Text='<%# Eval("FirstName") & " " & Eval("LastName") %>'></asp:HyperLink></ItemTemplate></asp:TemplateField>
                        </Columns>
                    <EditRowStyle BackColor="#999999" />
                    <EmptyDataTemplate>
                        Your search has yielded no results.<br /> Please try again.
                    </EmptyDataTemplate>
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                </asp:GridView>
                <asp:SqlDataSource ID="SearchByDateAndFaculty" runat="server" ConnectionString="<%$ ConnectionStrings:AppointmentsConnectionString %>"
                    ProviderName="<%$ ConnectionStrings:AppointmentsConnectionString.ProviderName %>"
                    SelectCommand="SELECT [ID], [Fkid_Faculty], [Fkid_UserId], [AppointmentDate], [TimeSlot], [Place], [FirstName], [LastName], [FacultyName] FROM [Test2AppointmentsAndLecturerDetailsQuery] WHERE (UniversityName = ?) AND (AppointmentDate = ?) AND (Fkid_Faculty = ?)">
                    <SelectParameters>
                        <asp:SessionParameter Name="UniversityName" SessionField="University" />
                        <asp:QueryStringParameter Name="AppointmentDate" QueryStringField="date" />
                        <asp:QueryStringParameter Name="Fkid_Faculty" QueryStringField="faculty" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </asp:View>
            <asp:View ID="SearchByNameDateAndFacultyView" runat="server">
                <asp:GridView ID="SearchByNameDateAndFacultyGridView" runat="server" EnableModelValidation="True"
                    CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" AllowSorting="True"
                    AutoGenerateColumns="False" DataSourceID="SearchByNameDateAndFaculty">
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <Columns>
                    <asp:BoundField DataField="ID" HeaderText="Appointment ID" Visible="False" />
                        <asp:BoundField DataField="AppointmentDate" HeaderText="Date" SortExpression="AppointmentDate" />
                        <asp:BoundField DataField="TimeSlot" HeaderText="Time" SortExpression="TimeSlot" />
                        <asp:BoundField DataField="Place" HeaderText="Place" SortExpression="Place" />
                        <asp:TemplateField HeaderText="Tutor Name"><ItemTemplate><asp:HyperLink ID="HyperLink1" runat="server" ToolTip="Click to view profile page"
                                    NavigateUrl='<%# Eval("Fkid_UserId", "BookAppointment.aspx?ID={0}") %>' Text='<%# Eval("FirstName") & " " & Eval("LastName") %>'></asp:HyperLink></ItemTemplate></asp:TemplateField>
                        <asp:TemplateField HeaderText="Faculty" SortExpression="FacultyName"><EditItemTemplate><asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FacultyName") %>'></asp:TextBox></EditItemTemplate><ItemTemplate><asp:HyperLink ID="HyperLink1" runat="server" ToolTip="View all available appointments in this faculty"
                                    NavigateUrl='<%# Eval("Fkid_Faculty", "BookAppointment.aspx?faculty={0}") %>' Text='<%# Eval("FacultyName") %>'></asp:HyperLink></ItemTemplate></asp:TemplateField>
                    </Columns>
                    <EditRowStyle BackColor="#999999" />
                    <EmptyDataTemplate>
                        Your search has yielded no results.<br /> Please try again.
                    </EmptyDataTemplate>
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                </asp:GridView>
                <asp:SqlDataSource ID="SearchByNameDateAndFaculty" runat="server" ConnectionString="<%$ ConnectionStrings:AppointmentsConnectionString %>"
                    ProviderName="<%$ ConnectionStrings:AppointmentsConnectionString.ProviderName %>"
                    SelectCommand="SELECT [ID], [Fkid_Faculty], [Fkid_UserId], [AppointmentDate], [TimeSlot], [Place], [FirstName], [LastName], [FacultyName] FROM [Test2AppointmentsAndLecturerDetailsQuery] WHERE (UniversityName = ?) AND ((FirstName LIKE '%' + ? + '%') OR (LastName LIKE '%' + ? + '%')) AND (AppointmentDate = ?) AND (Fkid_Faculty = ?)">
                    <SelectParameters>
                        <asp:SessionParameter Name="UniversityName" SessionField="University" />
                        <asp:QueryStringParameter Name="FirstName" QueryStringField="name" />
                        <asp:QueryStringParameter Name="LastName" QueryStringField="name" />
                        <asp:QueryStringParameter Name="AppointmentDate" QueryStringField="date" />
                        <asp:QueryStringParameter Name="Fkid_Faculty" QueryStringField="faculty" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </asp:View>
        </asp:MultiView>
    </div>
    <asp:SqlDataSource ID="FacultyDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:AppointmentsConnectionString %>"
        ProviderName="<%$ ConnectionStrings:AppointmentsConnectionString.ProviderName %>"
        SelectCommand="SELECT * FROM [Faculties] WHERE ([UniversityName] = ?)">
        <SelectParameters>
            <asp:SessionParameter Name="UniversityName" SessionField="University" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SearchByUniversity" runat="server" ConnectionString="<%$ ConnectionStrings:AppointmentsConnectionString %>"
        ProviderName="<%$ ConnectionStrings:AppointmentsConnectionString.ProviderName %>"
        SelectCommand="SELECT [ID], [AppointmentDate], [TimeSlot], [Place], [FirstName], [LastName] FROM [TestAppointmentsAndLecturerDetailsQuery]">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AppointmentsConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:AppointmentsConnectionString.ProviderName %>" 
        SelectCommand="SELECT * FROM [TestAppointmentsAndLecturerDetailsQuery] WHERE (([AppointmentDate] &gt;= ?) AND ([Booked] = ?) AND ([UniversityName] = ?) AND (([LastName] LIKE '%' + ? + '%') OR ([FirstName] LIKE '%' + ? + '%')))">
        <SelectParameters>
            <asp:ControlParameter ControlID="lbl_TodaysDate" Name="AppointmentDate" 
                PropertyName="Text" Type="DateTime" />
            <asp:Parameter DefaultValue="False" Name="Booked" Type="Boolean" />
            <asp:SessionParameter Name="UniversityName" SessionField="University" 
                Type="Int32" />
            <asp:QueryStringParameter Name="LastName" QueryStringField="name" 
                Type="String" />
            <asp:QueryStringParameter Name="FirstName" QueryStringField="name" 
                Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
    <br />
    <asp:Label ID="lbl_UserUniversity" runat="server" Visible="True"></asp:Label>
    <script type="text/javascript">
        function checkDate(sender, args) {
            if (sender._selectedDate < new Date()) {
                document.getElementById("lbl_DateError").innerHTML = "Date has already passed. Please choose a later date."
                document.getElementById("lbl_DateError").style.display = 'block';
                //                alert("You cannot select a day earlier than today!");
                //                document.getElementById().innerHTML = "You cannot select a day earlier than today";
                //                document.getElementById().style.display = 'block';
                //document.getElementById("invalidDate").style.display="block"
                sender._selectedDate = new Date();
                // set the date back to the current date
                sender._textbox.set_Value(sender._selectedDate.format(sender._format))
            }
            else {
                document.getElementById("lbl_DateError").style.display = 'none';
            }
        }
    </script>
    <br />
    <asp:Label ID="lbl_SelectedRow" runat="server"></asp:Label>
    <br />
    <asp:Label ID="lbl_TodaysDate" runat="server"></asp:Label>
</asp:Content>
